package fag.core.model;

import java.awt.image.BufferedImage;
import java.io.Serializable;

public class SerializableImage implements Serializable {

	private static final long serialVersionUID = 6392533270630759L;
	int width;
	int height;
	int[] pixels;

	public SerializableImage() {
		
		width = 0;
		height = 0;
		pixels = new int[0];
	}
	public SerializableImage(BufferedImage bi) {
		
		width = bi.getWidth();
		height = bi.getHeight();
		pixels = new int[width * height];
		bi.getRGB(0,0,width,height,pixels,0,width);
	}

	public BufferedImage getBufferedImage() {
		
		if(width == 0) {
			
			return null;
		}
		
		BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
		bi.setRGB(0,0,width,height,pixels,0,width);
		return bi;
	}

}

